﻿using System;
using System.Runtime.InteropServices;
namespace LEDHelper
{
    #region====WX LED==============
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct LEDBlock
    {
        [FieldOffset(0)]
        public Int32 nStartX;  			/// 区域的开始X坐标
        [FieldOffset(4)]
        public Int32 nStartY;				/// 区域的开始Y坐标
        [FieldOffset(8)]
        public Int32 nWidth; 				/// 区域的宽度
        [FieldOffset(12)]
        public Int32 nHeight;  			/// 区域的高度
    }
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct ClockDescriptor
    {
        [FieldOffset(0)]
        public Int32 nClockType;      // 时钟类型(1表示表盘时钟 0表示电子时针)
        // 当nClockType为0时生效，只使用以下字段4字节中的低字节，用该字节的低7位
        // 从低到高分别表示秒，分，时，日，月，年， 星期，如果位等于1表示需要显示，// 0表示不显示，比如01111110表示要显示星期，年，月，日，时，分，不显示秒
        [FieldOffset(4)]
        public Int32 nShowFormat; 	/// 0:只显示年月日 1:只显示时分秒 2:0和1的组合，即显示年月日又显示分秒时
        [FieldOffset(8)]
        public Int32 nScaleColor; 			/// 表盘刻度线的颜色
        [FieldOffset(12)]
        public Int32 nBoundColor;			/// 表盘边框线颜色
        [FieldOffset(16)]
        public Int32 nHourColor; 			/// 表盘时针颜色
        [FieldOffset(20)]
        public Int32 nMinuteColor; 		/// 表盘分针颜色
        [FieldOffset(24)]
        public Int32 nSecondColor; 		/// 表盘秒针颜色
    }
    /*
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct FontDescriptor
    {
        //[FieldOffset(0)]
        //[MarshalAs(UnmanagedType.U1, SizeConst = 16)]
        [FieldOffset(0)]
        public string szFontName; // 字体名称
        [FieldOffset(16)]
        public Int32 lFontSize;     // 字体大小
        [FieldOffset(20)]
        public Int32 lFontColor;  // 字体颜色
        [FieldOffset(24)]
        public Int32 nBold;           // 是否粗体(1表示粗体 0表示不是粗体
        [FieldOffset(28)]
        public Int32 nStrick;            // 是否斜体(1表示斜体 0表示不是斜体)
        [FieldOffset(32)]
        public Int32 nUnderline;  // 是否加下划线(1表示加下划线 0表示不加下划
    }
    */
    public struct FontDescriptor
    {
 
        public string szFontName; // 字体名称
       
        public Int32 lFontSize;     // 字体大小
        
        public Int32 lFontColor;  // 字体颜色
      
        public Int32 nBold;           // 是否粗体(1表示粗体 0表示不是粗体
    
        public Int32 nStrick;            // 是否斜体(1表示斜体 0表示不是斜体)
   
        public Int32 nUnderline;  // 是否加下划线(1表示加下划线 0表示不加下划
    }
    #endregion
    #region========StructLayout===========
    public struct Rect
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Ansi)]
    public struct SRECT
    {
        [FieldOffset(0)]
        public Int32 left;
        [FieldOffset(4)]
        public Int32 top;
        [FieldOffset(8)]
        public Int32 right;
        [FieldOffset(12)]
        public Int32 bottom;
    } 
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct LPSYSTEMTIME
    {
        Int32 wYear;
        Int32 wMonth;
        Int32 wDayOfWeek;
        Int32 wDay;
        Int32 wHour;
        Int32 wMinute;
        Int32 wSecond;
        Int32 wMilliseconds;
    }
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
    public struct PDeviceParam
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 devType; //通讯设备类型 
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Speed; //通讯速度(仅对串行通讯有用) 
        [MarshalAs(UnmanagedType.I4)]
        public Int32 ComPort; //本地端口(对串行通讯为：串口号；对UDP通讯为：本地端口号，一般要大于1024) 
        [MarshalAs(UnmanagedType.I4)]
        public Int32 FlowCon; //远程端口号(对UDP通讯有用，必须为6666) 
        [MarshalAs(UnmanagedType.I4)]
        public Int32 locPort; //未用 
        [MarshalAs(UnmanagedType.I4)]
        public Int32 rmtPort;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 memory;
        [MarshalAs(UnmanagedType.I4, SizeConst = 6)]
        public Int32 Reserved;
    }
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct PNotifyMessage
    {
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Message;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Command;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Result;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Status;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Address;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Size;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Buffer;
        public PDeviceParam param;
        [MarshalAs(UnmanagedType.U1, SizeConst = 16)]
        public char Host;
        [MarshalAs(UnmanagedType.I4)]
        public Int32 Port;
    }
    #endregion
    public static partial class LEDAPI
    {
        public const int WM_USER = 0x0400;
        public const int WM_LED_NOTIFY = WM_USER + 1;

        public const int WM_WINDOWPOSCHANGED = 0x0047;
        public const int WM_WINDOWPOSCHANGING = 0x0046;
        public const int WM_NCMOUSEMOVE = 0xa0;
        public const int WM_NCLBUTTONDOWN = 0xA1;
        public const int WM_NCLBUTTONUP = 0xA2;
        public const int WM_NCLBUTTONDBLCLK = 0xA3;
        public const int WM_NCRBUTTONDOWN = 0xA4;
        public const int WM_NCRBUTTONUP = 0xA5;
        public const int WM_CAPTURECHANGED = 0x0215;
        public const int WM_EXITSIZEMOVE = 0x0232;
        public const int WM_ENTERSIZEMOVE = 0x0231;
        public const int WM_MOVE = 0x0003;
        public const int WM_MOVING = 0x0216;
        public const int WM_KILLFOCUS = 0x0008;
        public const int WM_SETFOCUS = 0x0007;
        public const int WM_ACTIVATE = 0x0006;
        public const int WM_NCHITTEST = 0x0084;

        public const int WA_INACTIVE = 0x0000;

        public const int WM_NULL = 0x0000;
        public const int WM_CREATE = 0x0001;
        public const int WM_DESTROY = 0x0002;
        public const int WM_SIZE = 0x0005;
        public const int GWL_WNDPROC = (-4);

        //显示屏类型
        public const int FONT_SET_16 = 0;           //16点阵字符
        public const int FONT_SET_24 = 1;          //24点阵字符

        public const int PKC_QUERY = 4;
        public const int PKC_ADJUST_TIME = 6;
        public const int PKC_GET_POWER = 9;
        public const int PKC_SET_POWER = 10;
        public const int PKC_GET_BRIGHT = 11;
        public const int PKC_SET_BRIGHT = 12;

        //通讯方式
        public const Int32 DEVICE_TYPE_COM = 0;
        public const Int32 DEVICE_TYPE_UDP = 1;
        public const Int32 DEVICE_TYPE_485 = 2;

        //串行通讯速度
        public const int SBR_9600 = 0;            //串口速率9600
        public const int SBR_14400 = 1;             //14400
        public const int SBR_19200 = 2;             //串口速率19200
        public const int SBR_38400 = 3;             //串口速率38400
        public const int SBR_57600 = 4;             //串口速率57600
        public const int SBR_115200 = 5;             //串口速率115200

        //播放类型常量
        public const int ROOT_PLAY = 0X11;       //下发节目为播放数据
        public const int ROOT_DOWNLOAD = 0X12;        //下发节目为保存并播放

        public const int SCREEN_UNICOLOR = 1;       //单色显示屏
        public const int SCREEN_COLOR = 2;       //双色显示屏
        public const int SCREEN_FULLCOLOR = 3;       //全彩色显示屏
        public const int SCREEN_GRAY = 4;       //256级灰度屏

        //响应消息
        public const int LM_RX_COMPLETE = 1;
        public const int LM_TX_COMPLETE = 2;
        public const int LM_RESPOND = 3;
        public const int LM_TIMEOUT = 4;
        public const int LM_NOTIFY = 5;
        public const int LM_PARAM = 6;
        public const int LM_TX_PROGRESS = 7;
        public const int LM_RX_PROGRESS = 8;

        //时间格式定义，用于AddDateTime函数中format参数
        public const int DF_YMD = 1;       //年月日 “2004年12月31日”
        public const int DF_HN = 2;       //时分    “19:20″
        public const int DF_HNS = 3;       //时分秒 “19:20:30″
        public const int DF_Y = 4;       //年      “2004″
        public const int DF_M = 5;       //月      “12″ “01″ 注意：始终显示两位数字
        public const int DF_D = 6;       //日
        public const int DF_H = 7;       //时
        public const int DF_N = 8;       //分
        public const int DF_S = 9;      //秒
        public const int DF_W = 10;       //星期    “星期三”

        //正计时、倒计时format参数
        public const int CF_DAY = 0;               //天数
        public const int CF_HOUR = 1;               //小时数
        public const int CF_HMS = 2;               //时分秒
        public const int CF_HM = 3;               //时分
        public const int CF_MS = 4;               //分秒
        public const int CF_S = 5;               //秒

        //电源状态
        public const int LEM_BUFFER_FULL = 1;        //错误代码：发送缓冲满
        public const int LED_POWER_ON = 1;        //显示屏电源打开
        public const int LED_POWER_OFF = 0;        //显示屏电源已关闭
    } 
}